package com.cter.thinkingInSpringBoot;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


//Configuration 表示这是一个配置类
@Configuration
//启动Swagger2的相关功能
@EnableSwagger2
public class Swagger {
	 
	     @Bean
	     public Docket createRestApi() {
	        return new Docket(DocumentationType.SWAGGER_2)
	                .apiInfo(apiInfo())
	                .select()
	                .apis(RequestHandlerSelectors.basePackage("com.cter.thinkingInSpringBoot.controller"))//指定生成API文档的包名
	                .paths(PathSelectors.any())//指定生成API的路径。按路径生成API可支持四种模式
	                .build();
	     }
	     //整个API的描述信息，即ApiInfo对象包括的信息，这部分信息会在页面上展示。
	     @SuppressWarnings("deprecation")
	     private ApiInfo apiInfo() {
	        return new ApiInfoBuilder()
	                .title("ThinkingInSpringBoot API")
	                .description("hinkingInSpringBoot API")
	                .termsOfServiceUrl("http://127.0.0.1:8081/")
	                .contact("Cter")
	                .version("1.0")
	                .build();
	    }
}
